package com.xqledu.admin.utils;


import lombok.Getter;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Value;

/**
 * @description: MD5工具类
 * @author: 向其林
 * @date: 2023/5/2 0002 21:16
 * @version: 1.0
 **/
public class MD5Util {
    //本地盐
    @Value("${userinfo.salt-before}")
    private static String saltBefore;
    @Value("${userinfo.salt-after}")
    private static String saltAfter;
    //生成md5密码
    private static String md5(String password){
        return DigestUtils.md5Hex(password);
    }
    //md5(pass)
    public static String inputPassToMidPass(String inputPass){
        String password = saltBefore+inputPass+saltAfter;
        return md5(password);
    }
    //md5(md5(pass+salt1)+salt2)
    public static String midPassToDBPass(String midPass,String salt){
        int i = (midPass+salt).length()%6;
        String str = salt.charAt(i) + midPass + salt.charAt(5);
        return md5(str);
    }

    public static String inputPassToDBPass(String inputPass,String salt){
        String pass = inputPassToMidPass(inputPass);
        String password = midPassToDBPass(pass, salt);
        return password;
    }
}
